//
//  NavigationController.m
//  Weibo
//
//  Created by Anasue on 9/9/15.
//  Copyright (c) 2015 Anasue. All rights reserved.
//

#import "NavigationController.h"

@interface NavigationController ()

@end

@implementation NavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }
    return self;
}

//该方法只会调用一次

+ (void)initialize
{
    [self setupNavigstionBarTheme];
    [self setupBarButtonItemTheme];
    
}

+ (void)setupNavigstionBarTheme
{
    UINavigationBar *appearance = [UINavigationBar appearance];
    if (!iOS7) {
        [appearance setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
    }
    //设置导航条的状态
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSForegroundColorAttributeName] = [UIColor blackColor];
    textAttr[NSFontAttributeName] = NavigationTitleFont;
    textAttr[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    [appearance setTitleTextAttributes:textAttr];

    
    
}

+ (void)setupBarButtonItemTheme
{
    //只需设置一次，可通用于整个程序
    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    
    //设置导航栏item的状态
    NSMutableDictionary *textAttr = [[NSMutableDictionary alloc]init];
    textAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    textAttr[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    [appearance setTitleTextAttributes:textAttr forState:UIControlStateNormal];
    //设置导航栏item的高亮状态
    NSMutableDictionary *highTextAttr = [[NSMutableDictionary alloc]init];
    highTextAttr[NSForegroundColorAttributeName] = [UIColor redColor];
    [appearance setTitleTextAttributes:highTextAttr forState:UIControlStateHighlighted];
    //设置导航栏item的不可点击状态
    NSMutableDictionary *disableTextAttr = [[NSMutableDictionary alloc]init];
    disableTextAttr[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [appearance setTitleTextAttributes:disableTextAttr forState:UIControlStateDisabled];
    
    /**设置背景**/
    // 技巧: 为了让某个按钮的背景消失, 可以设置一张完全透明的背景图片
    [appearance setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        
        //设置导航栏左右按钮
//        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"navigationbar_back"] style:UIBarButtonItemStyleDone target:<#(id)#> action:<#(SEL)#>
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_back" highImageName:@"navigationbar_back_highlighted" target:self action:@selector(back)];
        viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImageName:@"navigationbar_more" highImageName:@"navigationbar_more_highlighted" target:self action:@selector(more)];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back
{
    
    [self popViewControllerAnimated:YES];
}

- (void)more
{
    [self popToRootViewControllerAnimated:YES];
}









@end
